using System.Reflection;

namespace Microsoft.ConnectionEngine.SampleDeploymentManager
{
    internal static class ReflectionSupport
    {
        public static Assembly LoadAssembly(string type)
        {
            if (type.Contains(","))
            {
                string[] typeDescriptors = type.Split(',');

                return Assembly.Load(typeDescriptors[1]);
            }

            return Assembly.Load(type);
        }

        public static object CreateInstance(string type)
        {
            Assembly assembly = LoadAssembly(type);

            return CreateInstance(assembly, type);
        }

        public static object CreateInstance(Assembly assembly, string type)
        {
            if (type.Contains(","))
            {
                string[] typeDescriptors = type.Split(',');

                return assembly.CreateInstance(typeDescriptors[0]);
            }

            return assembly.CreateInstance(type);
        }
    }
}
